package com.utonw.carloan.function;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.utonw.carloan.R;

/**
 * Created by SEELE on 2017/4/1.
 */

public class UIFunction {

    private Dialog sLoadingDialog;

    //生成一个自定义Dialog
    private Dialog showLoadingDialog(Context context, String msg) {

        LayoutInflater inflater = LayoutInflater.from(context);
        View v = inflater.inflate(R.layout.dialog_loading, null);// 得到加载view
        LinearLayout layout = (LinearLayout) v.findViewById(R.id.dialog_view);// 加载布局
        // main.xml中的ImageView
        TextView tipTextView = (TextView) v.findViewById(R.id.tipTextView);// 提示文字
        tipTextView.setText(msg);// 设置加载信息

        // 创建自定义样式dialog
        sLoadingDialog = new Dialog(context, R.style.loading_dialog);

        sLoadingDialog.setCancelable(false);// 不可以用“返回键”取消
        sLoadingDialog.setContentView(layout, new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.FILL_PARENT,
                LinearLayout.LayoutParams.FILL_PARENT));// 设置布局
        return sLoadingDialog;

    }

    public void showProgressDialog(Context context, String msg) {
        showLoadingDialog(context, msg).show();
    }

    public void dissmissProgressDialog() {
        sLoadingDialog.cancel();
        sLoadingDialog=null;
    }

}
